package com.amit.struts;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.validator.Field;
import org.apache.commons.validator.ValidatorAction;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;

public class JLCFieldChecks 
{
	
	public void validateEnquiryId(Object obj,ValidatorAction va, Field f,ActionErrors
			errors,HttpServletRequest req)
	{
		
		System.out.println("validateenquiryid");
		String enquiryId=req.getParameter("enquiryId");
		
		if(enquiryId==null || enquiryId.length()==0)
		{
			errors.add("enquiryId", new ActionError("error.enquiryId.required"));
		}
		
		else if(!enquiryId.startsWith("E-"))
		{
			errors.add("enquiryId", new ActionError("error.enquiryId.format1"));
		}
		
		else
		{
			String p2=enquiryId.substring(2);
			try
			{
				int x=Integer.parseInt(p2);
				if(x<1001)
				{
					errors.add("enquiryId", new ActionError("error.enquiryId.format2"));
				}
			}
			catch (Exception e) 
			{
			errors.add("enquiryId", new ActionError("error.enquiryId.format3"));
				
			}
		}
		
	}
	
	
	
	public void validateTimings(Object obj,ValidatorAction va, Field f,ActionErrors
			errors,HttpServletRequest req)
	{
		System.out.println("validate timings");
		String timings=req.getParameter("timings");
		System.out.println(timings);
		if(timings==null || timings.length()==0)
		{
			System.out.println("null");
			
			errors.add("timings", new ActionError("error.timings.required"));
		
		}
		
	}
	

}
